const app = getApp()
import util from '../../../utils/util'
import {
  GetIssueDetail,
  GetIssueHandleDetail
} from '../../../config/api'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    member_storge: '',

    id: '',
    handle_uid:'', // 回复人id
    detail: '', // 事件详情
    member_list:'',
    imgs: [],
    count: 0,
    compressImgsSizeArr: [],
    grider_storge: {
      // id: 9,
      // pid: 8,
      // name: '王群',
      // vollege_id: 6,
      // town_id: 5
    }, // 网格员缓存信息
    content: '',
    showView: true, // 是否隐藏弹出层
    handleInfo:null,
    memberList:null,

    handleInfo2:'', // 二级接收人数据
    color:'blue'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('options', options)
    let grider_storge = wx.getStorageSync('grider')
    let member_storge = wx.getStorageSync('member')

    this.setData({
      id: options.id,
      grider_storge: grider_storge,  // 正式打开
      member_storge: member_storge
    })

    this.getDetail();
  },

  getDetail() {
    let that = this;
    util.apiRequest(GetIssueDetail, { id: that.data.id }, null).then(r => {
      console.log('事件详情：', r)
      that.setData({
        detail: r.data.data.event,
        member_list: r.data.data.memberList,
        handle_uid:r.data.data.memberList[0].id
      })
      this.getMemberReply(1);
    })
  },

  // 预览事件内容图片
  previewAttach: function (e) {
    let that = this;
    var index = e.currentTarget.dataset.index;
    console.log('预览index', index);
    let imgs = that.data.detail.attach_arr;
    // console.log('imgs', that.data.Imgs);
    wx.previewImage({
      //当前显示图片
      current: imgs[index],
      //所有图片
      urls: imgs
    })
  },

  // 预览事件处理图片
  previewReplyImg: function (e) {
    console.log('预览处理图片e:', e)
    let that = this;
    var index = e.currentTarget.dataset.index;
    var pindex = e.currentTarget.dataset.pindex;

    console.log('aa预览index', index);

    let imgs = this.data.detail.handle_log[pindex].attach

    wx.previewImage({
      //当前显示图片
      current: imgs[index],
      //所有图片
      urls: imgs
    })
  },

  checkMemberReply(e){  // 点击查看某人回复
    let step = e.currentTarget.dataset.step;
    this.setData({
      handle_uid: e.currentTarget.dataset.handle_uid,
    })
    this.getMemberReply(step);
  },

  // 遮罩层隐藏
  // close: function () {
  //   let that = this;
  //   that.setData({
  //     showView: (!that.data.showView)
  //   })
  // },

  getMemberReply(step){ // 获取默认回复
    let that =this;
    let params ={
      event_id:that.data.id,
      handle_uid: that.data.handle_uid
    }
    util.apiRequest(GetIssueHandleDetail, params,null).then(r => {
      if(step == 1){
        that.setData({
          handleInfo: r.data.data.handleInfo,
          memberList: r.data.data.memberList
        })
      }else{
        that.setData({
          handleInfo2: r.data.data.handleInfo,
          //memberList: r.data.data.memberList
        })
      }
     
      console.log('i某个人的回复',r)
    })
  }




})